package whisper.service.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * Created by JT on 2017/11/2.
 */
@Configuration
public class DbConfig {

    @Bean(name = "DATASOURCE_CODER")
    @Primary
    @ConfigurationProperties(prefix = "db.datasource")
    public DataSource coderDataSource() {
        return new HikariDataSource();
    }

    @Bean(name = "JDBC_CODER")
    @Primary
    public JdbcTemplate coderJdbcTemplate(@Qualifier("DATASOURCE_CODER") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

}
